import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { registerMicroApps, start, initGlobalState } from 'qiankun';

const data = {
  data: {
    age: 90
  }
}
const actions = initGlobalState(data);
actions.onGlobalStateChange((state, prev) => {
  // state: 变更后的状态; prev 变更前的状态
  console.log('父级：', state.data);
});
window.actions = actions;

registerMicroApps([
  {
    name: 'vue1',
    entry: '//localhost:5174',
    container: '#team1',
    activeRule: '/team1',
    loader: (loading) => {
      console.info(`主应用 loading1: ${loading}`);
    },
    props: {
      router,
      data
    },
  },
  {
    name: 'vue2',
    entry: '//localhost:5175',
    container: '#team2',
    activeRule: '/team2',
    loader: (loading) => {
      console.info(`主应用 loading2: ${loading}`);
    },
    props: {
      router,
      data
    },
  },
]);

start({
  singular: false,
  sandbox: {
    experimentalStyleIsolation: true,
  },
});

const app = createApp(App)
app.use(router)
app.mount('#app')